Column

Chart A

Column

Chart B

Chart C

---
title: "Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
---

```{r, include=FALSE}
library(flexdashboard)
library(tidyverse)
library("p8105.datasets")
library(plotly)

data("instacart")
```

Column {data-width=500}
-----------------------------------------------------------------------

### Chart A

```{r}
instacart %>% 
  filter(department == "alcohol") %>%
  count(product_name, aisle) %>% 
  mutate(rank = min_rank(rank(desc(n))),
         aisle = recode(aisle,
                        "beers coolers" = "Beer",
                        "red wines" = "Red Wine",
                        "specialty wines champagnes" = "Specialty Wines/Champagnes",
                        "spirits" = "Spirit",
                        "white wines" = "White Wine")) %>%
  filter(rank < 50) %>%
  mutate(product_name = fct_rev(fct_reorder(product_name, n))) %>% 
  plot_ly(x = ~product_name, y = ~n, color = ~aisle, type = "bar", colors = "Set2") %>%
  layout(title = "Top 50 Ordered Alcoholic Beverages",
         xaxis = list(title = "Name of Product"),
         yaxis = list(title = "Number Ordered"),
         legend = list(x = 0.5, y = 0.9),
         hoverlabel = list(bordercolor = "transparent",
                           font = list(color = "white")))
```

Column {data-width=500}
-----------------------------------------------------------------------

### Chart B

```{r}
instacart %>%
  filter(department == "alcohol") %>%
  count(product_name, aisle) %>% 
  mutate(rank = min_rank(rank(desc(n))),
         aisle = recode(aisle,
                        "beers coolers" = "Beer",
                        "red wines" = "Red Wine",
                        "specialty wines champagnes" = "Specialty Wines/Champagnes",
                        "spirits" = "Spirit",
                        "white wines" = "White Wine")) %>%
  filter(rank <= 100) %>%
  plot_ly(y = ~n, color = ~aisle, type = "box", colors = "Set2") %>%
  layout(title = "Frequency of Orders by Type of Alcohol",
         xaxis = list(title = "Type of Alcohol"),
         yaxis = list(title = "Number Ordered"),
         hoverlabel = list(bordercolor = "transparent",
                           font = list(color = "white")))
```

### Chart C

```{r}
instacart %>%
  filter(department == "alcohol") %>%
  count(aisle, order_hour_of_day) %>% 
  mutate(rank = min_rank(rank(desc(n))),
         aisle = recode(aisle,
                        "beers coolers" = "Beer",
                        "red wines" = "Red Wine",
                        "specialty wines champagnes" = "Specialty Wines/Champagnes",
                        "spirits" = "Spirit",
                        "white wines" = "White Wine"),
         text_label = str_c("Time of Day: ", order_hour_of_day, "\nNumber Ordered: ", n)
         ) %>%
  filter(rank <= 1000) %>%
  plot_ly(
    x = ~order_hour_of_day, y = ~n, type = "scatter", mode = "line",
    color = ~aisle, text = ~text_label, colors = "Set2"
  ) %>%
  layout(title = "Frequency of Orders by Hour of Day",
         xaxis = list(title = "Hour of Day"),
         yaxis = list(title = "Number Ordered"),
         hoverlabel = list(bordercolor = "transparent",
                           font = list(color = "white")))
```